Completed
Push — master ( 77b412...0a81cb )
by Sander
04:08
created

angular.controller(ꞌMainCtrlꞌ)   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 57

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 57
rs 9.0309
cc 4
nc 8
nop 7

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
/**
2
 * Nextcloud - passman
3
 *
4
 * @copyright Copyright (c) 2016, Sander Brand ([email protected])
5
 * @copyright Copyright (c) 2016, Marcos Zuriaga Miguel ([email protected])
6
 * @license GNU AGPL version 3 or any later version
7
 *
8
 * This program is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Affero General Public License as
10
 * published by the Free Software Foundation, either version 3 of the
11
 * License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU Affero General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Affero General Public License
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 *
21
 */
22
23
(function () {
24
	'use strict';
25
26
	/**
27
	 * @ngdoc function
28
	 * @name passmanApp.controller:MainCtrl
29
	 * @description
30
	 * # MainCtrl
31
	 * Controller of the passmanApp
32
	 */
33
	angular.module('passmanApp')
34
		.controller('MainCtrl', ['$scope', '$rootScope', '$location', 'SettingsService', '$window', '$interval', '$filter', function ($scope, $rootScope, $location, SettingsService, $window, $interval, $filter) {
35
			$scope.selectedVault = false;
36
37
			$scope.http_warning_hidden = true;
38
			if ($location.$$protocol === 'http' && $location.$$host !== 'localhost' && $location.$host !== '127.0.0.1') {
39
				$scope.using_http = true;
40
				$scope.http_warning_hidden = false;
41
42
			}
43
44
			$rootScope.$on('settings_loaded', function(){
45
				if (SettingsService.getSetting('disable_contextmenu') === '1' || SettingsService.getSetting('disable_contextmenu') === 1) {
46
					document.addEventListener('contextmenu', function (event) {
47
						event.preventDefault();
48
					});
49
				}
50
				if (SettingsService.getSetting('https_check') === '0' || SettingsService.getSetting('https_check') === 0) {
51
					$scope.http_warning_hidden = true;
52
				}
53
			});
54
55
			$rootScope.setHttpWarning = function (state) {
56
				$scope.http_warning_hidden = state;
57
			};
58
59
			$rootScope.$on('app_menu', function (evt, shown) {
60
				$scope.app_sidebar = shown;
61
			});
62
63
			$rootScope.$on('logout', function () {
64
				$scope.selectedVault = false;
65
			});
66
67
			var tickSessionTimer = function(){
68
				if($scope.session_time_left){
69
					$scope.session_time_left--;
70
					var session_time_left_formatted = $filter('toHHMMSS')($scope.session_time_left);
71
					$scope.translationData = {
72
						session_time: session_time_left_formatted
73
					};
74
					$rootScope.$broadcast('logout_timer_tick_tack', $scope.session_time_left);
75
					if($scope.session_time_left === 0){
76
						$window.location.reload();
77
					}
78
				}
79
			};
80
81
			$scope.session_time_left = false;
82
			$scope.$on('logout_timer_set', function(evt, timer){
83
				$scope.session_time_left = timer;
84
				$scope.translationData = {
85
					session_time: timer
86
				};
87
				$interval(tickSessionTimer, 1000);
88
			});
89
90
		}]);
91
92
}());